package com.tqyan.model.enums;

import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;

/**
 * @description 小说类型
 * <p> <功能详细描述> </p>
 *
 * @author 陈晨
 * @date 2023/6/13 17:01
 */
@Getter
@AllArgsConstructor
public enum NovelTypeEnum {

    LOVE(0, "爱情"),
    MARTIAL_ARTS(1, "武侠"),
    INFERENCE(2, "推理"),
    SCIENCE_FICTION(3, "科幻"),
    HISTORY(4, "历史"),
    SOCIETY(5, "社会"),
    ADVENTURE(6, "冒险"),
    MAGIC(7, "魔幻"),
    FAIRY_TALES(8, "童话"),
    SUSPENSE(9, "悬疑"),
    TERROR(10, "恐怖"),
    WAR(11, "战争"),
    XIAN_XIA(12, "仙侠"),
    SPORTS(13, "竞技"),
    PASS_THROUGH(14, "穿越"),
    ;

    private final int value;
    private final String desc;

    public static NovelTypeEnum get(Integer value) {
        if (null == value) {
            return null;
        }
        return Arrays.stream(NovelTypeEnum.values())
                .filter(e -> e.value == value).findFirst().orElse(null);
    }

    public static NovelTypeEnum getByDesc(String desc) {
        if (StringUtils.isBlank(desc)) {
            return null;
        }
        return Arrays.stream(NovelTypeEnum.values())
                .filter(e -> e.desc.equals(desc)).findFirst().orElse(null);
    }

    public static Integer getValueByDesc(String desc) {
        NovelTypeEnum getEnum = Arrays.stream(NovelTypeEnum.values())
                .filter(e -> e.desc.equals(desc)).findFirst().orElse(null);
        if (null == getEnum) {
            return null;
        }
        return getEnum.getValue();
    }

    @Override
    public String toString() {
        return JSONObject.toJSONString(this);
    }

}
